#!/bin/bash

#创建目录
cd /
mkdir -p /ipset/txt/
cd /ipset/txt/

#下载最新的ip list
curl -o all_cn_cidr.txt https://ispip.clang.cn/all_cn_cidr.txt
curl -o chinatelecom_cidr.txt https://ispip.clang.cn/chinatelecom_cidr.txt
curl -o unicom_cnc_cidr.txt https://ispip.clang.cn/unicom_cnc_cidr.txt
curl -o cmcc_cidr.txt https://ispip.clang.cn/cmcc_cidr.txt
curl -o crtc_cidr.txt https://ispip.clang.cn/crtc_cidr.txt
curl -o cernet_cidr.txt https://ispip.clang.cn/cernet_cidr.txt
curl -o gwbn_cidr.txt https://ispip.clang.cn/gwbn_cidr.txt
curl -o othernet_cidr.txt https://ispip.clang.cn/othernet_cidr.txt
curl -o hk_cidr.txt https://ispip.clang.cn/hk_cidr.txt
curl -o mo_cidr.txt https://ispip.clang.cn/mo_cidr.txt
curl -o tw_cidr.txt https://ispip.clang.cn/tw_cidr.txt
curl -o blacklist.txt https://gitee.com/xlkgh/pve-firewall-ipset/raw/master/deny-ip-list.txt

#删除文件
rm -f cluster.fw

#生成新的cluster.fw

#录入ipset
echo "[IPSET all_cn_cidr] # 中国大陆所有IP地址" > cluster.fw
echo "" >> cluster.fw
cat all_cn_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET chinatelecom_cidr] # 中国电信" >> cluster.fw
echo "" >> cluster.fw
cat chinatelecom_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET unicom_cnc_cidr] # 中国联通/网通" >> cluster.fw
echo "" >> cluster.fw
cat unicom_cnc_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET cmcc_cidr] # 中国移动" >> cluster.fw
echo "" >> cluster.fw
cat cmcc_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET crtc_cidr] # 中国铁通" >> cluster.fw
echo "" >> cluster.fw
cat crtc_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET cernet_cidr] # 中国教育网" >> cluster.fw
echo "" >> cluster.fw
cat cernet_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET gwbn_cidr] # 长城宽带/鹏博士" >> cluster.fw
echo "" >> cluster.fw
cat gwbn_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET othernet_cidr] # 中国其他ISP" >> cluster.fw
echo "" >> cluster.fw
cat othernet_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET hk_cidr] # 中国香港" >> cluster.fw
echo "" >> cluster.fw
cat hk_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET mo_cidr] # 中国澳门" >> cluster.fw
echo "" >> cluster.fw
cat mo_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET tw_cidr] # 中国台湾" >> cluster.fw
echo "" >> cluster.fw
cat tw_cidr.txt >>  cluster.fw
echo "" >> cluster.fw

echo "[IPSET blacklist] # 手动黑名单" >> cluster.fw
echo "" >> cluster.fw
cat blacklist.txt >>  cluster.fw
echo "" >> cluster.fw